//
//  HNDownLoadMusicWorld.m
//  XDEducation
//
//  Created by 星道 on 17/6/6.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "HNDownLoadMusicWorld.h"
#import "HNHappyFamilyMusicWorldModel.h"
#import "HNDownLoadFile.h"
#import "HNHappyFamilyMusicWorldCell.h"
#import "HNAudioPlayer.h"
@interface HNDownLoadMusicWorld ()
@property (nonatomic, strong) NSArray *DataArr;
@property (nonatomic, strong) HNHappyFamilyMusicWorldModel *TempPlayerModel;
@end

@implementation HNDownLoadMusicWorld

/** 界面即将消失时移除播放 */
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [HNAudioPlayer Close];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = @"已下载";
    
    self.DataArr = [HNDownLoadFile GetAllDownLoadMusic];
    
    self.tableView.tableHeaderView = [UIView new];
    
    self.tableView.tableFooterView = [UIView new];
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([HNHappyFamilyMusicWorldCell class]) bundle:nil] forCellReuseIdentifier:@"Cell"];
    
}



#pragma mark - 表单代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.DataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HNHappyFamilyMusicWorldCell *Cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    HNHappyFamilyMusicWorldModel *Model = self.DataArr[indexPath.row];
    Cell.MusicModel = Model;
    //操控
    Cell.ClickPlayer = ^(HNHappyFamilyMusicWorldModel *TempPlayerModel, BOOL IsSelfModel)
    {
        //按钮状态
        if (!IsSelfModel)
        {
        self.TempPlayerModel.IsPlay = !self.TempPlayerModel.IsPlay;
        self.TempPlayerModel = TempPlayerModel;
        }
        [self.tableView reloadData];
    };
    return Cell;
}


#pragma mark - Setter
@end
